# 动态规划50题 https://www.bilibili.com/video/BV1aa411f7uT
# 9/50 获取生成数组中的最大值
# leetcode第1646题: https://leetcode.cn/problems/get-maximum-in-generated-array/description/

def getMaximumGenerated(n: int) -> int:
    if n == 0:
        return 0
    if n == 1:
        return 1
    dp = [0] * (n + 1)
    dp[0] = 0
    dp[1] = 1
    result = 1
    for i in range(1, (n - 1) // 2 + 1):
        dp[2 * i] = dp[i]
        dp[2 * i + 1] = dp[i] + dp[i + 1]
        result = max(dp[2 * i + 1], result)
    return result


if __name__ == '__main__':
    print(getMaximumGenerated(7))  # 3
    print(getMaximumGenerated(3))  # 2
    print(getMaximumGenerated(2))  # 1
    print(getMaximumGenerated(0))  # 0
